﻿#ifndef C3FDCHARTWIDGET_H
#define C3FDCHARTWIDGET_H

#include <QWidget>
#include <QList>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_legend.h>
#include <qwt_legend_label.h>
#include "Common/Types.h"

namespace MainWidget
{
	class C3fdChartWidget : public QWidget
	{
		Q_OBJECT
	public:
		C3fdChartWidget(QStringList seriesTitles, bool showPoint = false, QWidget *parent = nullptr);
		virtual ~C3fdChartWidget();
		QStringList getSeriesTitles();

		void appendData(QVector<double> data);
		void setData(QList<QVector<double>> data);
		void saveImage(QString filePath, int width = 0, int height = 0, Common::AspectRatioMode mode = Common::AspectRatioMode::Undefined, int quality = -1);
		void showCurve(QwtPlotItem* item, bool on);
		void showCurve(QString title);

		void enableFocusSignal(bool enable);
		void enableLegendCheck(bool enable);
		void clearAllCurve();

	signals:
		void focusInSig(QWidget *, QString type = "qwt");

	public slots:
		void legendCheckedSlot(const QVariant &itemInfo, bool on, int index);

	protected:
		void focusInEvent(QFocusEvent *event) override;
		void focusOutEvent(QFocusEvent *event) override;
		void paintEvent(QPaintEvent* event) override;

	private:
		void initPlot();
		void rePlot();

	private:
		QWidget* m_ChartWidget = nullptr;
		QwtPlot *m_Plot = nullptr;
		QStringList m_SeriesTitles = {};
		QList<QwtPlotCurve *> m_Curves = {};
		QList<QVector<QPointF>> m_Datas = {};

		bool m_ShowPoint = false;
		bool m_IsFocus = false;
		bool m_EnableFocusSignal = false;
		bool m_EnableLegendCheck = false;
	};

}

#endif